package com.mobvel.zxstdzgl;

import net.youmi.android.appoffers.AppOffersManager;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.mobclick.android.MobclickAgent;
import com.waps.AppConnect;

public class MainActivity extends Activity {

//	private PreferencesHelper mHelper;

	private ImageView ivCover;
	private ImageButton ibRead;
	private RelativeLayout rlMore;
	
//	private AdTool mAdTool;

	public void onCreate(Bundle paramBundle) {
		super.onCreate(paramBundle);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.main);

		//waps
		AppConnect.getInstance(this);
		
		//youmi
//		AdManager.init(this, "d50f21c6b359c106", "1b0ad2947e2c81ea", 30, false);
//		AppOffersManager.init(this, "d50f21c6b359c106", "1b0ad2947e2c81ea", false);
		
//		mHelper = new PreferencesHelper(this);
		ivCover = (ImageView)findViewById(R.id.iv_cover);
		ivCover.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				
				Intent i = new Intent(MainActivity.this, ArticleListActivity.class);
				startActivity(i);
				
			}
		});
		
		ibRead = (ImageButton)findViewById(R.id.ib_read);
		ibRead.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				
				Intent i = new Intent(MainActivity.this, ArticleListActivity.class);
				startActivity(i);
				
			}
		});
		rlMore = (RelativeLayout)findViewById(R.id.rl_more);
		final TextView tvMore = (TextView)findViewById(R.id.tv_more);
		String offerSwitch = MobclickAgent.getConfigParams(this, "offer_switch");
		if(offerSwitch.equals("open")) {
			tvMore.setText(R.string.text_more);
			rlMore.setOnClickListener(new OnClickListener() {
				public void onClick(View v) {
					String offerId = MobclickAgent.getConfigParams(MainActivity.this, "offer_id");
					if(offerId.equals("waps")) {
						//waps
						AppConnect.getInstance(MainActivity.this).showOffers(MainActivity.this);
					}else {
						//youmi
						AppOffersManager.showAppOffers(MainActivity.this);
					}
				}
			});
		}else {
			tvMore.setText("退出");
			rlMore.setOnClickListener(new OnClickListener() {
				public void onClick(View v) {
					finish();
				}
			});
		}
		
//		mAdTool = new AdTool(this);
		
	}
	
	public void onResume() {
		super.onResume();
		
		MobclickAgent.onResume(this);
	}
	
	public void onPause() {
		super.onPause();
		
		MobclickAgent.onPause(this);
	}

	public void onDestroy() {
		//waps
		//AppConnect.getInstance(this).finalize();
		//admogo
//		AdMogoManager.clear();
		
		super.onDestroy();
	}

}